import {Menu} from "./Menu";
import  * as fs from "fs"
import {FileEx} from "./FileEx";

export class Temp {

    static temp = Menu.root + "/runtime/temp/";

    /**
     * 创建缓存目录
     */
    static create() {
        if (!fs.existsSync(Temp.temp)) {
            FileEx.mkdirsSync(Temp.temp)
            for (let i = 1; i <= 31; i++) {
                fs.mkdirSync(Temp.temp + i + "/");
            }
        }
    }

    /**
     * 获取当前缓存目录
     */
    static get() {
        let now = new Date();
        return Temp.temp + now.getDate() + "/";
    }

    /**
     * 清空2天前的缓存
     */
    static clear() {
        let now = new Date();
        now.setDate(now.getDate() - 2)
        FileEx.deleteFolderRecursive(Temp.temp + now.getDate() + "/");
    }
}